<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The SplString class</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="class.splbool.html">SplBool</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="book.stream.html">Streams</a></div>
 <div class="up"><a href="book.spl-types.html">SPL Types</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="class.splstring" class="reference">

 <h1 class="title">The SplString class</h1>
 
 
 <div class="partintro"><p class="verinfo">(PECL spl_types &gt;= 0.1.0)</p>


  <div class="section" id="splstring.intro">
   <h2 class="title">简介</h2>
   <p class="para">
    The SplString class is used to enforce strong typing of the string type.
   </p>
  </div>


  <div class="section" id="splstring.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass"></div>


    <div class="classsynopsisinfo">
     <span class="ooclass">
      <strong class="classname">SplString</strong>
     </span>
     
     <span class="ooclass">
      <span class="modifier">extends</span>
      <a href="class.spltype.html" class="classname">SplType</a>
     </span>
     {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Constants */</div>
    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">integer</span>
      <var class="fieldsynopsis_varname"><a href="class.splstring.html#splstring.constants.default"><var class="varname">__default</var></a></var>
     <span class="initializer"> = 0</span>
    ;</div>

    
    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 继承的方法 */</div>
    <div class="methodsynopsis dc-description">
   <span class="methodname"><a href="spltype.construct.html" class="methodname">SplType::__construct</a></span>
    ([ <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$initial_value</code></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$strict</code></span>
  ]] )</div>


   }</div>


  </div>
  

  <div class="section" id="splstring.constants">
   <h2 class="title">预定义常量</h2>
   <dl>


    
     <dt id="splstring.constants.default"><strong><code>SplString::__default</code></strong></dt>

     <dd>

      <p class="para"/>
     </dd>

    

   </dl>

  </div>


 
  <div class="section" id="splstring.examples">
   <h2 class="title">范例</h2>
   <p class="para">
    <div class="example" id="example-3909">
     <p><strong>Example #1 <strong class="classname">SplString</strong> usage example</strong></p>
     <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$string&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SplString</span><span style="color: #007700">(</span><span style="color: #DD0000">"Testing"</span><span style="color: #007700">);<br /><br />try&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$string&nbsp;</span><span style="color: #007700">=&nbsp;array();<br />}&nbsp;catch&nbsp;(</span><span style="color: #0000BB">UnexpectedValueException&nbsp;$uve</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$uve</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getMessage</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$string</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$string</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;Outputs&nbsp;"Testing"<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
     </div>

     <div class="example-contents"><p>以上例程会输出：</p></div>
     <div class="example-contents screen">
<div class="cdata"><pre>
Value not a string
object(SplString)#1 (1) {
  [&quot;__default&quot;]=&gt;
  string(7) &quot;Testing&quot;
}
Testing
</pre></div>
     </div>
    </div>
   </p>
  </div>
 

 </div>

</div>
<hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="class.splbool.html">SplBool</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="book.stream.html">Streams</a></div>
 <div class="up"><a href="book.spl-types.html">SPL Types</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
